//
//  ItemFrame.m
//  XiaoHongShu
//
//  Created by Jason on 2022/6/20.
//

#import "ItemFrame.h"
#import <UIKit/UIKit.h>
#import "MainDataModel.h"

#define itemMarigin 5
@implementation ItemFrame

- (void)setMainDataModel:(MainDataModel *)mainDataModel {
    _mainDataModel = mainDataModel;
    //设置控件的frame和行高
    [self setupFrame];
}

//设置控件的frame和行高
- (void)setupFrame {
    // 没必要for
    ImagesModel *images = _mainDataModel.images.firstObject;
    //图片宽度比例
    CGFloat ratio = ((kSPScreenWidth - itemMarigin * 3) / 2) / images.width;
    //图片高度
    CGFloat imgViewH = images.height * ratio;
    //图片宽
    CGFloat imgViewW = (kSPScreenWidth - itemMarigin * 3) / 2;
    //图片frame
    _imgViewFrame = CGRectMake(0, 0, imgViewW, imgViewH);
   // NSLog(@"imgViewH = %f, imgViewW = %f",imgViewH, imgViewW);
    
    //视频头像
    CGFloat vedioW = 15;
    CGFloat vedioH = 15;
    CGFloat vedioX = CGRectGetWidth(_imgViewFrame) - 10 - vedioW;
    CGFloat vedioY = CGRectGetMinY(_imgViewFrame) + 10;
    _vedioImgViewFrame = CGRectMake(vedioX, vedioY, vedioW, vedioH);
    
    
    //是否赞助label
    CGFloat adsLabelW = 30;
    CGFloat adsLabelH = 15;
    CGFloat adsLabelX = CGRectGetWidth(_imgViewFrame) - 10 - adsLabelW;
    CGFloat adsLabelY = CGRectGetHeight(_imgViewFrame) - 10 - adsLabelH;
    _adsLabelFrame = CGRectMake(adsLabelX, adsLabelY, adsLabelW, adsLabelH);
  
    //正文frame
    _textLabelFrame = CGRectMake(5, CGRectGetMaxY(_imgViewFrame), imgViewW - 10, 50);
    
    //用户头像
    CGFloat userImgViewW = 20;
    CGFloat userImgViewH = userImgViewW;
    _userImgViewFrame = CGRectMake(5, CGRectGetMaxY(_textLabelFrame) + userImgViewH / 4, userImgViewW, userImgViewH);
    
    //用户名
    CGFloat userNameLabelW = 100;
    CGFloat userNameLabelH = 30;
    CGFloat userNameLabelX = CGRectGetWidth(_userImgViewFrame) + 10;
    _userNameLabelFrame = CGRectMake(userNameLabelX, CGRectGetMaxY(_textLabelFrame), userNameLabelW, userNameLabelH);
    
    
    //点赞数frame
    CGFloat likeBtnX = CGRectGetMaxX(_userNameLabelFrame);
    CGFloat likeBtnH = 30;
  //  NSLog(@"likeBtnX = %f", likeBtnX);
    _likeBtnFrame = CGRectMake(likeBtnX, CGRectGetMaxY(_textLabelFrame), imgViewW - likeBtnX, likeBtnH);
    
   
    CGFloat itemHeight = 0;
    itemHeight = CGRectGetMaxY(_likeBtnFrame);
    _itemHeight = itemHeight;
  //  NSLog(@"itemHeight = %f",_itemHeight);
  
}

@end
